//
//  FoundServiceCell.m
//  PigMarket
//
//  Created by 张敬 on 2019/9/3.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "FoundServiceCell.h"

@implementation FoundServiceCell

- (void)setupUI{
    
    [self addSubview:self.shopIcon];
    [self addSubview:self.locationIcon];
    [self addSubview:self.shopNameLab];
    [self addSubview:self.visitorsLab];
    [self addSubview:self.addShopBtn];

}

- (void)setupLayout{
    
    {
        _shopIcon.size = CGSizeMake(50, 50);
        _shopIcon.mj_x = 15;
        _shopIcon.mj_y = 10;
    }
    
    {
        //店铺名称
        _shopNameLab.frame = CGRectMake(0, 0, KScreenWidth, 30);
        [_shopNameLab sizeToFit];
        _shopNameLab.mj_x = 15 + _shopIcon.right;
        _shopNameLab.mj_y = 10;
    }

    {
        //店铺内容
        _visitorsLab.frame = CGRectMake(0, 0, KScreenWidth, 30);
        [_visitorsLab sizeToFit];
        _visitorsLab.mj_x = _shopNameLab.right + 5;
        _visitorsLab.mj_y = 13;
        _visitorsLab.width += 10;
        _visitorsLab.height += 5;

    }
    
    {
        _locationIcon.size = CGSizeMake(16, 16);
        _locationIcon.mj_x = _shopIcon.right + 15;
        _locationIcon.mj_y = _shopNameLab.bottom + 8;
    }
    
    {
        _addShopBtn.size = CGSizeMake(56, 26);
        _addShopBtn.mj_y = 23;
        _addShopBtn.mj_x = KScreenWidth - _addShopBtn.width - 15;
    }
    
    {
        _shopLocationLab.mj_y = _locationIcon.mj_y;
        _shopLocationLab.mj_x = _locationIcon.right + 5;
        _shopLocationLab.height = _locationIcon.height;
        _shopLocationLab.width = KScreenWidth - _shopLocationLab.left - _addShopBtn.width - 30;
    }

}


#pragma mark - setter

- (void)setItem:(FoundMapNearByItem *)item{
    
    _shopNameLab.text = item.nickName;
    _visitorsLab.text = [NSString stringWithFormat:@"%@人", item.num];
    _shopLocationLab.text = [JTool iSNull:item.nowPosition] ?@"" :item.nowPosition;
    [_shopIcon sd_setImageWithURL:[NSURL URLWithString:item.headImg] placeholderImage:[UIImage imageNamed:@"head_blank_mine"]];
    
    if ([item.joinIf integerValue] == 0) {
        [self.addShopBtn setTitle:@"加入" forState:UIControlStateNormal];
    }else{
        [self.addShopBtn setTitle:@"退出" forState:UIControlStateNormal];
    }
    
    [self setupLayout];
}


#pragma mark - getter

- (UIImageView *)shopIcon{
    
    if (!_shopIcon) {
        _shopIcon = [[UIImageView alloc] init];
        _shopIcon.image = [UIImage imageNamed:@"head_blank_mine"];
        [self addShadowAndCircleCorner:_shopIcon.layer corner:25];
    }
    return _shopIcon;
}


- (UIImageView *)locationIcon{
    
    if (!_locationIcon) {
        _locationIcon = [[UIImageView alloc] init];
        _locationIcon.image = [UIImage imageNamed:@"address_tip"];
    }
    return _locationIcon;
}

//店铺名称
- (UILabel *)shopNameLab{
    
    if (!_shopNameLab) {
        _shopNameLab = [[UILabel alloc] init];
        _shopNameLab.textColor = UIColorFromRGB(0x172434);
        _shopNameLab.font = mFont(16);
    }
    return _shopNameLab;
}



//店铺内容
- (UILabel *)visitorsLab{
    
    if (!_visitorsLab) {
        _visitorsLab = [[UILabel alloc] init];
        _visitorsLab.font = mFont(10);
        _visitorsLab.textColor = UIColorFromRGB(0x9C9C9C);
        _visitorsLab.backgroundColor = UIColorFromRGB(0xF2F4F7);
        _visitorsLab.textAlignment = 1;
        [self addShadowAndCircleCorner:_visitorsLab.layer corner:3];
        
    }
    return _visitorsLab;
}

//店铺距离
- (UILabel *)shopLocationLab{
    
    if (!_shopLocationLab) {
        _shopLocationLab = [[UILabel alloc] init];
        _shopLocationLab.font = mFont(13);
        _shopLocationLab.textColor = UIColorFromRGB(0x999999);
        _shopLocationLab.textAlignment = 0;
    }
    return _shopLocationLab;
}


- (UIButton *)addShopBtn{
    
    if (!_addShopBtn) {
        _addShopBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_addShopBtn setTitleColor:mMainColor forState:UIControlStateNormal];
        _addShopBtn.titleLabel.font = mFont(12);
        _addShopBtn.layer.borderColor = mMainColor.CGColor;
        _addShopBtn.layer.borderWidth = 1;
        [_addShopBtn setTitle:@"加入" forState:UIControlStateNormal];
        [self addShadowAndCircleCorner:_addShopBtn.layer corner:5];
        
        @weakify(self);
        _addShopBtn.tapBlock = ^{
            @strongify(self);
            if (self.dealServiceBlock) {
                self.dealServiceBlock();
            }
        };
    }
    return _addShopBtn;
}

@end
